<!--  -->
<template>
  <div class='ratings'
       ref='ratings'>
    <div class="content">
      <div class="overview">
        <div class="left">
          <h1 class='score'>{{seller.score}}</h1>
          <div class="title">综合评分</div>
          <div class="rank">高于周边{{seller.rankRate}}%商家</div>
        </div>
        <div class="right">
          <div class="score-wrapper">
            <span class='title'>服务态度</span>
            <div class="star">
              <star :size='36'
                    :score='seller.serviceScore'></star>
            </div>
            <span class='score'>{{seller.serviceScore}}</span>
          </div>
          <div class="score-wrapper">
            <span class='title'>商品评分</span>
            <div class="star">
              <star :size='36'
                    :score='seller.foodScore'></star>
            </div>
            <span class='score'>{{seller.foodScore}}</span>
          </div>
          <div class="score-wrapper">
            <span class='title'>送达时间</span>

            <span class='score'>{{seller.deliveryTime}}分钟</span>
          </div>
        </div>
      </div>
      <split></split>
      <div class="ratingselect">
        <ratingselect :selectType='selectType'
                      :onlyContent='onlyContent'
                      :ratings='ratings'
                      :desc='desc'
                      @typeselect='typechange'
                      @contentselect='contentchange'></ratingselect>
      </div>

      <div class="rating-wrapper"
           ref='ratingWrapper'>
        <ul>
          <li v-for='(rating,index) in ratings'
              :key='index'
              v-show='needShow(rating.rateType,rating.text)'
              class='item'>
            <div class="avatar">
              <img :src="rating.avatar">
            </div>
            <div class="content">
              <div class="name">{{rating.username}}</div>
              <div class="star-wrapper">
                <star :size='24'
                      :score="rating.score"></star>
              </div>
              <div class="text">{{rating.text}}</div>
            </div>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script type='text/ecmascript-6'>
import star from '../star/star.vue'
import ratingselect from '../ratingselect/ratingselect'
import split from '../split/split'
import BScroll from 'better-scroll'
const ALL = 2
export default {
  data () {
    return {
      ratings: [],
      selectType: ALL,
      onlyContent: true,
      desc: {
        all: '全部',
        positive: '推荐',
        negative: '吐槽'
      }
    }
  },
  created () {
    this.$http.get('/api/ratings').then((response) => {
      response = response.body
      if (response.errno === 0) {
        this.ratings = response.data
        this.$nextTick(() => {
          if (!this.scroll) {
            this.scroll = new BScroll(this.$refs.ratings, {
              click: true
            })
          } else {
            this.scroll.refresh()
          }
        })
      }
    })
  },
  props: {
    seller: {
      type: Object
    }
  },
  components: {
    star,
    ratingselect,
    split
  },
  methods: {
    typechange (type) {
      this.selectType = type
      this.$nextTick(() => {
        this.scroll.refresh()
      })
    },
    contentchange () {
      this.onlyContent = !this.onlyContent
      this.$nextTick(() => {
        this.scroll.refresh()
      })
    },
    needShow (rateType, text) {
      if (this.onlyContent && !text) {
        return false
      }
      if (this.selectType === ALL) {
        return true
      } else {
        return this.selectType === rateType
      }
    }
  }
}

</script>
<style lang='stylus' scoped>
@import '../../common/stylus/base.styl'
@import '../../common/stylus/mixin.styl'
@import '../../common/stylus/icon.styl'
.ratings
  position absolute
  top 174px
  left 0
  bottom 0
  width 100%
  overflow hidden
  .overview
    display flex
    padding 18px 0
    .left
      width 137px
      flex 0 0 137px
      border-right 1px
      text-align center
      @media only screen and (max-width: 320px)
        width 120px
        flex 0 0 120px
      .score
        line-height 28px
        font-size 24px
        color rgb(255, 153, 0)
        margin-bottom 8px
      .title
        line-height 12px
        font-size 14px
        color rgb(7, 17, 27)
        margin-bottom 8px
        font-weight 700
      .rank
        font-size 10px
        line-height 10px
        color rgb(147, 153, 159)
        padding-bottom 6px
    .right
      flex 1
      padding-left 24px
      @media only screen and (max-width: 320px)
        padding-left 12px
      .score-wrapper
        margin-bottom 8px
        .title
          line-height 18px
          font-size 12px
          color rgb(7, 17, 27)
        .star
          line-height 18px
          display inline-block
          vertical-align top
        .score
          line-height 18px
          display inline-block
          vertical-align top
          font-size 12px
  .rating-wrapper
    padding 0 18px
    .item
      display flex
      padding 6px 0
      .avatar
        img
          width 24px
          height 24px
      .content
        .name
          vertical-align top
          font-size 10px
          color rgb(147, 153, 159)
        .star-wrapper
          margin-top 0
        .text
          font-size 14px
          color rgb(7, 17, 27)
          padding 6px 0
</style>
